package gui;

/**
 * Created with IntelliJ IDEA.
 * User: benoitchassinat
 * Date: 02/02/2014
 * Time: 18:37
 * To change this template use File | Settings | File Templates.
 */


import java.awt.GridLayout;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.*;

import montecarloMultithread.MultiThreadMontCarlo;
import montecarloSinglethread.SingleThreadMontCarlo;


public class GUIApp {


    private static void BuildGUI(int width, int height)
            throws NumberFormatException, IOException {
        JFrame frame = new JFrame("MonteCarlo Method Application");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(width, height);

        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new GridLayout(0, 2));

        Object[][] TempTab= readFile();
        Object[] param= new Object[6];
        int i = 0;



        String[] SingleChoiceTable = new String[2];
        SingleChoiceTable[0] = "Single";
        SingleChoiceTable[1] = "Multithreaded";
        final JComboBox SingleMultiList = new JComboBox(SingleChoiceTable);
        JLabel SingleMultiLabel = new JLabel("Which version you want to try ? ");
        mainPanel.add(SingleMultiLabel);
        mainPanel.add(SingleMultiList);

        // Call/Put
        String[] callputChoiceTable = new String[2];
        callputChoiceTable[0] = "Call";
        callputChoiceTable[1] = "Put";
        final JComboBox CallPutList = new JComboBox(callputChoiceTable);
        JLabel CallPutLabel = new JLabel("is it a Call or Put? ");
        mainPanel.add(CallPutLabel);
        mainPanel.add(CallPutList);


    }




        private static Object[][] readFile() throws NumberFormatException,
            IOException {

        Object[][] testValues = new Object[8][6];
        BufferedReader reader = new BufferedReader(new FileReader(
                "Test.txt"));

        String paramLine = null;
        String[] paramTable = null;
        int nbLine = 0;

        //parsing
        while ((paramLine = reader.readLine()) != null) {

            paramTable = paramLine.split(",");

            for (int i = 0; i < paramTable.length; i++) {

                if (nbLine == 0 || nbLine == 1 || nbLine == 6 || nbLine == 7) {
                    testValues[nbLine][i] = Integer
                            .parseInt(paramTable[i]);
                } else if (nbLine == 2 || nbLine == 3 || nbLine == 4 || nbLine == 5)
                    testValues[nbLine][i] = Double
                            .parseDouble(paramTable[i]);
                else
                    System.out.println("Error in the txt file.");
            }

            nbLine++;
        }

        reader.close();

        return testValues;
    }





  /*  public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    BuildGUI(900, 600);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

    }

}

    */